import { delToken, getToken, setToken } from "@/utils/storage";
import { login } from "@/api/index";
import { Message } from "element-ui";

export default {
  namespaced: true,
  state: {
    token: getToken(),
    list: [],
  },
  mutations: {
    pushtoken(state, newtoken) {
      setToken(newtoken);
      state.token = newtoken;
    },
    loginOut(state) {
      delToken();
      state.token = "";
    },
    getList(state, arr) {
      state.list = arr;
    },
  },
  actions: {
    async login(ctx, data) {
      const res = await login(data);
      ctx.commit("pushtoken", res.data.token);
      Message.success("登录成功");
    },
    fn() {
      console.log(1);
    },
  },
  getters: {},
};
